package emergence.entities;

import emergence.entities.MobClass.MobClass;
import emergence.entities.attribute.MobStatSet;
import emergence.game.Game;
import emergence.game.InputHandler;
import emergence.game.level.Level;

public class Player extends Mob {

    private boolean inputLock = false;
    private final InputHandler input;
    private final Game game;

    public Player(Level level, InputHandler input, MobClass mobClass, MobStatSet stats, Game game) {
        super(level, "Player", mobClass, stats);
        this.input = input;
        this.game = game;
    }

    @Override
    public void tick() {
        super.tick();

        if (!inCombat && !inputLock) {
            if (input.up.isPressed()) {
                ya--;
            }
            if (input.down.isPressed()) {
                ya++;
            }
            if (input.left.isPressed()) {
                xa--;
            }
            if (input.right.isPressed()) {
                xa++;
            }

            if (((xa != 0) || (ya != 0)) && !moving) {
                if (ya != 0) move(0, ya);
                else move(xa, 0);
            }
        }
        
        if (!moving) {
            if (game.hasSelection()) {
                switch (game.lastSelectionType()) {
                    case ATTACK:
                        this.attack(game.getSelection());
                        break;
                }
            }
        }
    }
    
    @Override
    public boolean isFriendsWith(Mob other) {
        return other instanceof Player;
    }
    
    public void setInputLock(boolean lock) {
        this.inputLock = lock;
    }
    
}
